﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RegisterationCommon.Common;
using System.Data;

namespace RegisterationCommon.Notice
{
    /// <summary>
    /// 公告信息实体类
    /// </summary>
    public class Notice
    {
        #region 局部变量
        //主键，自动编号
        private int _ID = 0;
        //公告标题
        private string _Tile = "";
        //接受对象0全部1学校2家长
        private int _Recrive = 0;
        //公告内容
        private string _Content = "";
        //公告状态0显示1不显示
        private bool _Status = false;
        //发布时间
        private DateTime _Time = DateTime.Now;
        #endregion

        #region 属性列表
        /// <summary>
        /// 发布时间
        /// </summary>
        public DateTime Time
        {
            get { return _Time; }
            set { _Time = value; }
        }
        /// <summary>
        /// 公告状态0显示1不显示
        /// </summary>
        public bool Status
        {
            get { return _Status; }
            set { _Status = value; }
        }
        /// <summary>
        /// 公告内容
        /// </summary>
        public string Content
        {
            get { return _Content; }
            set { _Content = value; }
        }
        /// <summary>
        /// 接受对象0全部1学校2家长
        /// </summary>
        public int Recrive
        {
            get { return _Recrive; }
            set { _Recrive = value; }
        }
        /// <summary>
        /// 公告标题
        /// </summary>
        public string Tile
        {
            get { return _Tile; }
            set { _Tile = value; }
        }
        /// <summary>
        /// 主键，自动编号
        /// </summary>
        public int ID
        {
            get { return _ID; }
            set { _ID = value; }
        }
        #endregion

        #region 方法列表

        #region 查询公告信息列表
        /// <summary>
        /// 查询公告信息列表
        /// </summary>
        /// <param name="RP">数据集</param>
        /// <returns>返回JSON格式的字符串</returns>
        public string GetHelpSubjectList(RParams RP)
        {
            //查询当前页
            DataTable dt = DBAction.ExecSP("sp_select_page", RP).Tables[0];
            //查询条件的总条数
            int totalCount = DBAction.GetDTFromSQL("select * from " + ETableName.Notice + " where " + RP.GetSqlParameter("Where").Value).Rows.Count;
            //返回Json
            return DBAction.DataTableToJson(dt, true, totalCount);
        }
        #endregion

        #region 根据ID查询公告信息
        /// <summary>
        /// 根据ID查询公告信息
        /// </summary>
        /// <param name="leaveID">公告信息编号</param>
        /// <returns>查询成功返回true,否则返回false</returns>
        public bool GetHelpSubjectByID(int noticeID)
        {
            DataTable dt = DBAction.GetDTFromSQL("Select * From " + ETableName.Notice + " where id=" + noticeID);
            if (dt.Rows.Count < 1)
            {
                return false;
            }
            this._ID = noticeID;
            this._Tile = Convert.ToString(dt.Rows[0]["Tile"]);
            this._Content = Convert.ToString(dt.Rows[0]["Content"]);
            this._Recrive = Convert.ToInt32(dt.Rows[0]["Recrive"]);
            this._Status = Convert.ToBoolean(dt.Rows[0]["Status"]);
            this._Time = Convert.ToDateTime(dt.Rows[0]["Time"]);
            return true;
        }
        #endregion

        #region 添加公告信息
        /// <summary>
        /// 添加公告信息
        /// </summary>
        /// <returns>添加成功返回true,否则返回false</returns>
        public bool AddNotice()
        {
            RParams RP = new RParams();
            RP.Add("Tile", this._Tile, SqlDbType.VarChar);
            RP.Add("Content", this._Content, SqlDbType.VarChar);
            RP.Add("Recrive", this._Recrive, SqlDbType.Int);
            RP.Add("Status", this._Status, SqlDbType.Bit);
            RP.Add("Time", this._Time, SqlDbType.DateTime);
            return AddNotice(RP);
        }
        /// <summary>
        /// 添加公告信息
        /// </summary>
        /// <param name="RP">数据集</param>
        /// <returns>添加成功返回true,否则返回false</returns>
        public bool AddNotice(RParams RP)
        {
            return DBAction.Insert(ETableName.Notice, RP);
        }
        #endregion

        #region 根据ID删除公告信息
        /// <summary>
        /// 根据ID删除公告信息
        /// </summary>
        /// <param name="helpID">公告信息编号</param>
        /// <returns>删除成功返回true,否则返回false</returns>
        public bool DelNotice(int noticeID)
        {
            RParams RP = new RParams();
            RP.Add("ID", noticeID, SqlDbType.Int);
            string whereFields = "ID=@ID";
            return DBAction.Delete(ETableName.Notice, whereFields, RP);
        }
        /// <summary>
        /// 根据指定的公告ID列表删除公告信息
        /// </summary>
        /// <param name="studentIDList"></param>
        /// <returns></returns>
        public bool DelNoticeList(string IDList)
        {
            return DBAction.Delete("Notice", "id in (" + IDList + ")");
        }
        /// <summary>
        /// 根据ID删除公告信息
        /// </summary>
        /// <returns>删除成功返回true,否则返回false</returns>
        public bool DelNotice()
        {
            return DelNotice(this._ID);
        }
        #endregion

        #region 修改公告信息
        /// <summary>
        /// 修改公告信息
        /// </summary>
        /// <returns>修改成功返回true,否则返回false</returns>
        public bool UpdNotice()
        {
            RParams RP = new RParams();
            RP.Add("ID", this._ID, SqlDbType.Int);
            RP.Add("Tile", this._Tile, SqlDbType.VarChar);
            RP.Add("Content", this._Content, SqlDbType.VarChar);
            RP.Add("Recrive", this._Recrive, SqlDbType.Int);
            RP.Add("Status", this._Status, SqlDbType.Bit);
            RP.Add("Time", this._Time, SqlDbType.DateTime);
            string colFields = "Tile,Content,Recrive,Status,Time";
            string whereFields = "ID=@ID";
            return UpdNotice(colFields, whereFields, RP);
        }
        /// <summary>
        /// 修改公告信息
        /// </summary>
        /// <param name="colFields">修改的列</param>
        /// <param name="whereFields">修改条件</param>
        /// <param name="RP">数据集</param>
        ///  <returns>修改成功返回true,否则返回false</returns>
        public bool UpdNotice(string colFields, string whereFields, RParams RP)
        {
            return DBAction.Update(ETableName.Notice, colFields, whereFields, RP);
        }
        #endregion

        /// <summary>
        /// 修改公告接受对象
        /// </summary>
        /// <returns>修改成功返回true,否则返回false</returns>
        public bool UpdNoticeRecriveByID()
        {
            RParams RP = new RParams();
            RP.Add("ID", this._ID, SqlDbType.Int);
            RP.Add("Recrive", this._Recrive, SqlDbType.Int);
            string colFields = "Recrive";
            string whereFields = "ID=@ID";
            return UpdNotice(colFields, whereFields, RP);
        }

        /// <summary>
        /// 修改公告状态
        /// </summary>
        /// <returns>修改成功返回true,否则返回false</returns>
        public bool UpdNoticeStatusByID()
        {
            RParams RP = new RParams();
            RP.Add("ID", this._ID, SqlDbType.Int);
            RP.Add("Status", this._Status, SqlDbType.Int);
            string colFields = "Status";
            string whereFields = "ID=@ID";
            return UpdNotice(colFields, whereFields, RP);
        }
        #endregion
    }
}
